﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>系统导航菜单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <div id="bDiv">
    </div>

    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body" style="padding-top:4%">
            <form id="AddForm" class="layui-form layui-col-space5">
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        菜单编码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="menuCode" name="menuCode" required="" autocomplete="off" class="layui-input">
                    </div>

                    <label for="L_email" class="layui-form-label">
                        菜单名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="menuName" name="menuName" required="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        菜单序号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="orderNum" name="orderNum" required="" placeholder="只允许输入数字" autocomplete="off" class="layui-input">
                        <input type="hidden" id="id" name="id">
                        <input type="hidden" id="oldMenu" name="oldMenu">
                    </div>
                    <label for="L_email" class="layui-form-label">
                        所属菜单
                    </label>
                    <div class="layui-input-inline">
                        <select name="parentMenu" id="parentMenu" lay-search="">
                            <option value="">请选择</option>
                        </select>

                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="L_email" class="layui-form-label">
                        菜单路径
                    </label>
                    <div class="layui-input-block">
                        <input type="text" id="menuPath" name="menuPath" required="" autocomplete="off" class="layui-input">
                    </div>

                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        菜单图标
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="menuIcon" name="menuIcon" required="" placeholder="参照框架CSS样式" autocomplete="off" class="layui-input">

                    </div>
                    <label for="L_email" class="layui-form-label">
                        是否启用
                    </label>
                    <div class="layui-input-inline">
                        <select name="status" id="status" class="valids"></select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        菜单类型
                    </label>
                    <div class="layui-input-block">
                        <input type="radio" name="mType" value="PC" title="PC菜单" checked />
                        <input type="radio" name="mType" value="APP" title="APP菜单" />
                    </div>
                </div>
            </form>
        </div>
    </div>

</body>
</html>

<script type="text/javascript">
    $(function () {
        var menuCode = getUrlVariable("menuCode");
        MenuInfo();
        BannerData("comUpdate", "bDiv");
        DictionaryDropDown("ct", "status", "Y");
        if (menuCode != "0") {
            $("input[ name='oldMenu']").val(menuCode);
            loadData(menuCode);
        }

    });

    // 保存数据
    function saveData() {
        $.ajax({
            url: "../System/SaveMenuInfo",
            data: { datas: JSON.stringify(FormToJson("AddForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.result) {
                    layer.msg("保存成功", { icon: 1 });
                } else {
                    layer.msg(data.message, { icon: 2 });
                }
            }
        });
    }

    //加载数据信息
    function loadData(mCode) {
        $.ajax({
            url: "../System/getMenuByCode",
            type: "post",
            data: { menuCode: mCode },
            success: function (data) {
                if (data.result) {
                    $.each(data.data[0], function (name, value) {
                        if (name == "parentMenu") {
                            $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                        } else if (name == "mType") {
                            if (value == "PC") {
                                $('input[name="mType"][value="PC"]').attr("checked", 'true');
                            }
                            if (value == "APP") {
                                $('input[name="mType"][value="APP"]').attr("checked", 'true');
                            }
                        } else if (name == "parValue") {
                            $("#parValue").html(value);
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    });
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }
    /**
     * 获取全部有效菜单
     * **/
    function MenuInfo() {
        $.ajax({
            url: "../System/getEnableMenuInfo",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.result) {
                    var datas = data.data;
                    for (var i = 0; i < datas.length; i++) {
                        $("#parentMenu").append("<option value=\"" + datas[i]["menuCode"] + "\" >" + datas[i]["menuName"] + "(" + datas[i]["menuCode"] + ")" + "</option>");
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }
</script>

